package com.his.registration.mapper;

import com.his.dto.CheckResult;
import com.his.dto.InspectionCharge;
import com.his.dto.InspectionResult;
import com.his.registration.pojo.CheckRequest;
import com.his.registration.pojo.InspectionRequest;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @BelongsProject: workspace-idea
 * @BelongsPackage: com.his.registration.mapper
 * @Author: ZhangYing
 * @Date: 2023/7/2 16:08
 * @Description:
 */
@Mapper
public interface InspectionRequestMapper {
    //查询患者所有的检验费用
    @Select("select i.id,m.tech_name,m.tech_price,m.tech_type,i.creation_time,i.inspection_state from inspection_request i,medical_technology m where i.register_id=17 and i.medical_technology_id=m.id")
    public List<InspectionCharge> getInspectionFee(int registerId);

    //缴费
    @Select("update inspection_request set inspection_state=#{drugState} where id=#{id}")
    public int charge(String drugState,int id);

    //开设检验时：点击确认后在对应表中插入挂号id、医技id、开立时间、状态
    @Insert("INSERT INTO inspection_request (register_id, medical_technology_id,creation_time,inspection_state) VALUES (#{registerId},#{medicalTechnologyId},#{creationTime},#{inspectionState})")
    public int insert(int registerId, int medicalTechnologyId, LocalDateTime creationTime, String inspectionState);

    //得到刚刚插入的id
    @Select("SELECT LAST_INSERT_ID()")
    public int getInsertId();

    //在得到id的基础上添加其他数据
    public int updateOthers(int id,String inspectionInfo,String inspectionPosition,String inspectionRemark);

    //根据挂号id查询检验结果
    @Select("SELECT * FROM inspection_request where register_id=#{registerId}")
    public List<CheckRequest> getCheck(int registerId);

    //根据检查id查询
    @Select("select * from inspection_request where id=#{id}")
    public InspectionRequest selectById(int id);

    //根据id删除
    @Delete("delete from inspection_request where id=#{id}")
    public int deleteById(int id);

    //搜索挂号id对应的检验结果信息
    @Select("select m.tech_name,i.inspection_position,i.inspection_info,i.inspection_result,i.inspection_time,i.inspection_state from medical_technology m,inspection_request i where i.medical_technology_id=m.id and register_id=#{registerId}")
    public List<InspectionResult> getInspectionByRegisterId(int registerId);
}
